package com.chujian.Adapter;

import java.text.SimpleDateFormat;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chujian.model.Book;
import com.chujian.orderingsystem.R;

public class BookListAdapter extends BaseAdapter{
	private LayoutInflater mLayoutInflater;
	private Context context;
	private List<Book>mList;
	
	public BookListAdapter(Context context, List<Book> mList) {
		super();
		this.context = context;
		this.mList = mList;
		mLayoutInflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder=null;
		if(convertView==null){
			holder=new ViewHolder();
			convertView=mLayoutInflater.inflate(R.layout.book_list_seller_item, null);
			holder.tvUserPhone=(TextView) convertView.findViewById(R.id.tv_book_list_s_user_phone);
			holder.tvArriveTime=(TextView) convertView.findViewById(R.id.tv_book_list_s_arrive_time);
			holder.tvTableName=(TextView) convertView.findViewById(R.id.tv_book_list_s_table_name);
			holder.tvBookId=(TextView) convertView.findViewById(R.id.tv_book_list_s_book_id);
			holder.tvStatus=(TextView) convertView.findViewById(R.id.tv_book_list_s_status);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String arriveTime = df.format(new java.util.Date(mList.get(position).getArriveTime()));
		
		holder.tvUserPhone.setText(mList.get(position).getUserPhone());
		holder.tvArriveTime.setText(arriveTime);
		holder.tvTableName.setText(mList.get(position).getTableName());
		holder.tvBookId.setText(mList.get(position).getBookId()+"");
		
		if(mList.get(position).getBookStatus()==0){
			holder.tvStatus.setTextColor(Color.BLUE);
			holder.tvStatus.setText("未确认");
		}else if(mList.get(position).getBookStatus()==1){
			holder.tvStatus.setTextColor(Color.GREEN);
			holder.tvStatus.setText("已确认");
		}
		
		
		return convertView;
	}
	class ViewHolder{
		public TextView tvUserPhone;
		public TextView tvArriveTime;
		public TextView tvTableName;
		public TextView tvBookId;
		public TextView tvStatus;
	}

}
